package com.huaxin.crm.web.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.huaxin.crm.pojo.HxEmployee;
import com.huaxin.crm.pojo.HxEmployeeExample;
import com.huaxin.crm.service.HxEmployeeService;
import com.huaxin.crm.util.LayuiTableBean;

/**
 *
 * @版权: Copyright (c) 2016-2017 ****公司技术开发部
 * @author :Steven Liu
 * @E-mail:1661105301@qq.com
 * @版本: 1.0
 * @创建日期: 2018年1月2日 下午4:24:50
 * @ClassName HxEmployeeController
 * @类描述-Description: TODO
 * @修改记录:
 * @版本: 1.0
 */
@Controller
@RequestMapping("/employee")
public class HxEmployeeController {

	@Autowired
	HxEmployeeService hxEmployeeService;

	@RequestMapping("/listAll")
	public String listAll(Model model) {

		HxEmployeeExample example = new HxEmployeeExample();
		List<HxEmployee> selectByExample = hxEmployeeService
				.selectByExample(example);

		model.addAttribute("lists", selectByExample);
		System.out.println("~~");
		return "employee/listAll";
	}

	@RequestMapping("/listAllData")
	@ResponseBody
	public LayuiTableBean<HxEmployee> listAllData(Integer page, Integer limit) {

		HxEmployeeExample example = new HxEmployeeExample();
		List<HxEmployee> lists = hxEmployeeService.selectByExample(example);

		LayuiTableBean<HxEmployee> layuiTableBean = new LayuiTableBean<HxEmployee>(
				lists.size(), lists);

		return layuiTableBean;
	}

	@RequestMapping("/add")
	public String add() {
		return "employee/add";
	}

	@RequestMapping("/delete/{id}")
	@ResponseBody
	public String delet(@PathVariable String id) {
		System.out.println(id);
		return "ok";
	}

	@RequestMapping("/toUpdate/{id}")
	public String toUpdate(@PathVariable String id, Model model) {
		System.out.println(id);
		HxEmployee selectByPrimaryKey = hxEmployeeService
				.selectByPrimaryKey(id);

		model.addAttribute("bean", selectByPrimaryKey);

		return "employee/update";
	}

	@RequestMapping("/update")
	public String toUpdate(HxEmployee bean) {
		System.out.println(bean);
		return "employee/update";
	}
}
